home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d21
/
dvglue.arc
/
DEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-09
|
26KB
|
740 lines
/*
** DEMO.C - DESQview demonstration program.
** IBM Personal Computer - DESQview C Interface Demo.
** Written for Borland Turbo C v1.5.
*/
#include <stdio.h>
#include <dir.h>
#include <bios.h>
#include <io.h>
#include <string.h>
#include <stdlib.h>
#include "tvapi.h" /* types and function prototypes */
#include "tvstream.h"
#if __TURBOC__ != 1 && __TURBOC__ != 0x0100
unsigned _heaplen = 10240 ; /* only need 10K heap */
#endif
#define VERSION_STR "0.91"
/*===============================================================*/
#define STDERR 2
#define WR_STRC(f,s) write(f,s,sizeof(s)-1) /* string constant */
#define SO_STRC(s) WR_STRC(STDOUT,s) /* string con to STDOUT */
#define SE_STRC(s) WR_STRC(STDERR,s) /* string con to STDERR */
void write_int(int i)
{
char a[9] ;
itoa(i,a,10) ;
TVwin_swrite(NIL,a) ;
}
/*===============================================================*/
void stream_test(void)
{
int row, col ;
char old_title[24] ;
int old_frattr ;
int org_row, org_col ;
char buffer[10] ;
int i ;
TVwin_resize(NIL,13,66) ;
TVwin_move(NIL,7,5) ;
TVwin_cursor(NIL,0,0) ;
TVqry_origin(NIL,&org_row,&org_col) ;
TVwin_origin(NIL,org_row,org_col) ;
TVqry_title(NIL,old_title,sizeof(old_title)) ;
TVwin_title(NIL,"DV-GLUE v" VERSION_STR) ;
old_frattr = TVqry_frattr(NIL) ;
TVwin_frattr(NIL,9) ;
TVwin_clear(NIL) ;
TVwin_redraw(NIL) ;
TVwin_printf(NIL,"Window #%d, old name was %s, origin (%d,%d)\r\n", DVappnum(), old_title, org_row,org_col) ;
TVqry_cursor(NIL,&row,&col) ;
TVwin_printf(NIL,"Cursor position is (%d,%d)\r\n",row,col) ;
TVqry_position(NIL,&row,&col) ;
TVwin_printf(NIL,"Window is at (%d,%d) ",row,col) ;
TVqry_size(NIL,&row,&col) ;
TVwin_printf(NIL,"and is %dx%d",row,col) ;
TVqry_lsize(NIL,&row,&col) ;
TVwin_printf(NIL,"/%dx%d in phys/logical size\r\n",row,col) ;
TVwin_printf(NIL,"The current output attribute is %d\r\n",TVqry_attr(NIL)) ;
TVwin_printf(NIL,"The old frame attribute was %d\r\n",old_frattr) ;
TVwin_printf(NIL,"Control code processing is %s",TVqry_ctrl(NIL)?"on":"off") ;
TVwin_printf(NIL," and we are \r\n %s when writing\r\n",TVqry_leave(NIL)?
"leaving attributes untouched":"changing attributes") ;
TVwin_printf(NIL,"Using %s attributes\r\n",TVqry_logattr(NIL)?"logical":"physical") ;
TVwin_hcur(NIL) ;
TVwin_atread(NIL,FALSE) ;
TVqry_cursor(NIL,&row,&col) ;
TVwin_cursor(NIL,0,0) ;
TVwin_nread(NIL,(void *)buffer,sizeof(buffer)) ;
TVwin_cursor(NIL,row,col) ;
TVwin_printf(NIL,"First method read '%s' from screen\n",buffer) ;
TVwin_cursor(NIL,0,0) ;
TVwin_read(NIL,(void *)buffer,sizeof(buffer)) ;
TVwin_gotoxy(NIL,col,row+1) ;
TVwin_printf(NIL,"Second method read '%s' from screen\n",buffer) ;
TVwin_swrite(NIL,"\r\nPress a key to hide window, then another to unhide it....");
TVwin_hcur(NIL) ;
bioskey(0) ;
TVwin_hide(NIL) ;
bioskey(0) ;
TVwin_unhide(NIL) ;
TVwin_swrite(NIL,"\r\nPress a key to continue..." ) ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVqry_size(NIL,&row,&col) ;
for (i = 0 ; i < col ; i++)
{
TVsleep(5) ;
TVwin_scroll(NIL,0,0,row,col,SCRL_LEFT) ;
}
}
/*===============================================================*/
void timer_test(void)
{
OBJECT k, t, w ;
int left, elapsed ;
w = TVwin_new(NIL,5,46) ;
TVwin_clear(w) ;
TVposwin(w,NIL,PW_HCENTER|PW_VCENTER) ;
TVwin_cursor(w,0,0) ;
TVwin_origin(w,0,0) ;
TVwin_top(w) ;
TVwin_printf(w,"Press a few keys during the next ten seconds:"
"\r\n(this still doesn't work)") ;
k = TVkbd_new() ;
TVkbd_open(k,w) ; /* before connecting new kbd to window */
TVkbd_setflags(k,0x2004|KBD_ACTIVE) ;
t = TVtimer_new() ;
TVtimer_begin(t,1000) ; /* 10 seconds */
while ((left = (int) TVtimer_len(t)) > 0)
{
elapsed = (int) TVtimer_elapsed(t) ;
TVwin_cursor(w,3,0) ;
TVwin_printf(w,"Time left: %2d.%02d Keys pressed: %d\r\n Elapsed: %2d.%02d",
left/100, left%100, TVkbd_messages(k), elapsed/100,
elapsed%100) ;
}
TVtimer_free(t) ;
TVkbd_clear(k) ; /* get rid of typeahead */
TVwin_cursor(w,0,0) ;
TVwin_printf(w,"%5d keys left after clearing typeahead \r\n",TVkbd_messages(k));
while (bioskey(1)) /* brute-force keyboard clear */
bioskey(0) ;
TVsleep(100) ;
TVkbd_close(k) ;
TVkbd_free(k) ;
TVwin_free(w) ;
TVkbd_setflags(NIL,KBD_ACTIVE) ; /* open and make active again */
}
/*===============================================================*/
void far notify_func(void)
{
static NOTIFY_MSG msg ; /* must be static to be in DS since SS != DS */
/* in this routine even in small data models */
int i, len ;
/* at this point, we are on the private stack, not our own */
/* switching to our prior stack causes a crash */
/* NOTE: can't use TVwin_printf unless we can ensure that it isn't used in */
/* any routines which might be interrupted for this notification */
/* also need to be careful with any routines that need SS == DS in small */
/* data models */
while (TVmbx_size(NIL))
{
len = TVreadmail(NIL,(char *)&msg,sizeof(msg)) ;
TVwin_swrite(NIL,"\r\n \r") ;
switch (msg.event-MS_NOTIFY)
{
case TV_HMOVE:
case TV_VMOVE:
TVwin_swrite(NIL,"Hey, don't move me! Now at ") ;
write_int(msg.msg.movement.row) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.movement.col) ;
break ;
case TV_HSIZE:
case TV_VSIZE:
TVwin_swrite(NIL,"I liked my previous size! New size ") ;
write_int(msg.msg.resizing.rows) ;
TVwin_swrite(NIL," by ") ;
write_int(msg.msg.resizing.cols) ;
break ;
case TV_HSCROLL:
TVwin_swrite(NIL,"You scrolled me ") ;
if (msg.msg.scrolling.direction > 0)
TVwin_swrite(NIL,"right") ;
else if (msg.msg.scrolling.direction < 0)
TVwin_swrite(NIL,"left") ;
else
TVwin_swrite(NIL,"[done]") ;
break ;
case TV_VSCROLL:
TVwin_swrite(NIL,"You scrolled me ") ;
if (msg.msg.scrolling.direction > 0)
TVwin_swrite(NIL,"down") ;
else if (msg.msg.scrolling.direction < 0)
TVwin_swrite(NIL,"up") ;
else
TVwin_swrite(NIL,"[done]") ;
break ;
case TV_CLOSE:
TVwin_swrite(NIL,"You can't close me yet! Next time WILL close me") ;
TVwin_cancel(NIL,TV_CLOSE) ;
break ;
case TV_HIDE:
TVwin_swrite(NIL,"You hid me!") ;
break ;
case TV_HELP:
TVwin_swrite(NIL,"Sorry, no help available. Mouse at (") ;
write_int(msg.msg.help.mouse_row) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.help.mouse_col) ;
TVwin_swrite(NIL,")") ;
break ;
case TV_COLORS:
TVwin_swrite(NIL,"Was the color changed?") ;
break ;
case TV_SWITCHEDTO:
TVwin_swrite(NIL,"Thanks for making me active.") ;
break ;
case TV_SWITCHEDAWAY:
TVwin_swrite(NIL,"Hey, I want to stay active!") ;
break ;
case TV_VIDEOMODE:
TVwin_swrite(NIL,"New video mode is ") ;
write_int(msg.msg.video_mode) ;
break ;
case TV_SCISSORS_CUT:
TVwin_swrite(NIL,"Sorry, don't know how to cut (") ;
write_int(msg.msg.scissors.up_left_row) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col) ;
TVwin_swrite(NIL,") to (") ;
write_int(msg.msg.scissors.up_left_row + msg.msg.scissors.height - 1) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col + msg.msg.scissors.width - 1) ;
TVwin_swrite(NIL,")") ;
break ;
case TV_SCISSORS_COPY:
TVwin_swrite(NIL,"Sorry, don't know how to copy (") ;
write_int(msg.msg.scissors.up_left_row) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col) ;
TVwin_swrite(NIL,") to (") ;
write_int(msg.msg.scissors.up_left_row + msg.msg.scissors.height - 1) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col + msg.msg.scissors.width - 1) ;
TVwin_swrite(NIL,")") ;
break ;
case TV_SCISSORS_PASTE:
TVwin_swrite(NIL,"Sorry, don't know how to paste (") ;
write_int(msg.msg.scissors.up_left_row) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col) ;
TVwin_swrite(NIL,") to (") ;
write_int(msg.msg.scissors.up_left_row + msg.msg.scissors.height - 1) ;
TVwin_swrite(NIL,",") ;
write_int(msg.msg.scissors.up_left_col + msg.msg.scissors.width - 1) ;
TVwin_swrite(NIL,")") ;
break ;
case TV_MAINMENU:
TVwin_swrite(NIL,"Main menu popped up") ;
break ;
case TV_MENU_END:
TVwin_swrite(NIL,"Main menu put away") ;
break ;
default: TVwin_swrite(NIL,"Unknown event ") ;
write_int(msg.event) ;
TVwin_swrite(NIL,"! What happened?") ;
break ;
}
TVwin_swrite(NIL," [") ;
for (i = 0 ; i < len ; i++)
{
TVputchar(NIL,"0123456789ABCDEF"[((BYTE)(((char *)&msg)[i])) >> 4],15) ;
TVputchar(NIL,"0123456789ABCDEF"[((BYTE)(((char *)&msg)[i])) & 0x0F],15) ;
}
TVwin_swrite(NIL,"]") ;
}
}
void notify_test(void)
{
int i ;
TVwin_async(NIL,notify_func) ;
for (i = TV_HMOVE ; i <= TV_SWITCH ; i++)
{
TVwin_allow(NIL,i) ;
TVwin_notify(NIL,i) ;
}
TVwin_disallow(NIL,TV_QUIT) ;
TVwin_clear(NIL) ;
TVwin_cursor(NIL,0,0) ;
TVwin_origin(NIL,0,0) ;
TVwin_swrite(NIL,"Just try to do something to me! (including closing me)") ;
TVwin_cursor(NIL,4,0) ;
TVwin_swrite(NIL,"Press a key when done....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
for (i = TV_HMOVE ; i <= TV_SWITCH ; i++)
TVwin_cancel(NIL,i) ; /* cancel notification */
TVwin_allow(NIL,TV_QUIT) ;
TVwin_clear(NIL) ;
}
/*===============================================================*/
void pointer_test(void)
{
OBJECT p ;
int i, rows, cols ;
TVwin_title(NIL,"Mouse Demo") ;
TVwin_clear(NIL) ;
TVwin_origin(NIL,0,0) ;
TVwin_redraw(NIL) ;
p = TVptr_new() ;
TVptr_open(p,NIL) ;
TVptr_icon(p,'+') ;
TVqry_size(NIL,&rows,&cols) ;
TVwin_disallow(NIL,TV_HSIZE) ;
TVwin_swrite(NIL,"Please make sure mouse pointer is visible if you are\r\n"
"using a keyboard mouse, then press a key\r\n" ) ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVwin_swrite(NIL,"\r\nMoving mouse pointer to screen origin") ;
TVqry_position(NIL,&rows,&cols) ;
TVptr_goto(p,-rows,-cols) ;
TVsleep(150) ;
TVwin_swrite(NIL,"\r\nMoving mouse pointer to positions relative to window\r\n");
for (i = 0 ; i < rows ; i++)
{
TVptr_goto(p,i,i/2+1) ;
TVsleep(25) ;
}
TVwin_allow(NIL,TV_HSIZE) ;
TVptr_close(p) ;
TVptr_free(p) ;
if (TVisobj(p))
TVerrormsg(0,"Error--Pointer wasn't freed!",1,0,0,0) ;
else
{
TVwin_swrite(NIL,"\r\nPress a key to continue....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
}
TVwin_clear(NIL) ;
}
/*===============================================================*/
void multiwindow_test(void)
{
OBJECT win1 = TVwin_new(NIL,10,15) ;
OBJECT win2 = TVwin_new(NIL,5,20) ;
OBJECT win3 = TVwin_new(NIL,8,30) ;
TVwin_move(win1,6,60) ;
TVwin_title(win1,"Window 1") ;
TVwin_redraw(win1) ;
TVwin_move(win2,1,52) ;
TVwin_title(win2,"Window 2") ;
TVwin_redraw(win2) ;
TVwin_move(win3,4,40) ;
TVwin_title(win3,"Window 3") ;
TVwin_redraw(win3) ;
TVwin_title(NIL,"Multiwindow Demo") ;
TVwin_redraw(NIL) ;
TVsleep(150) ;
TVwin_reorder(win1,OBJSEG(win3),OBJSEG(win2),OBJSEG(TVmywindow()),OBJSEG(win1),0);
TVwin_swrite(win1,"Window 1 on top") ;
TVsleep(150) ;
TVwin_reorder(win3,OBJSEG(win2),OBJSEG(win1),OBJSEG(TVmywindow()),OBJSEG(win3),0);
TVwin_swrite(win3,"Window 3 on top") ;
TVsleep(150) ;
TVwin_reorder(win2,OBJSEG(win3),OBJSEG(TVmywindow()),OBJSEG(win1),OBJSEG(win2),0);
TVwin_swrite(win2,"Window 2 on top") ;
TVsleep(150) ;
TVwin_reorder(NIL,OBJSEG(win2),OBJSEG(win3),OBJSEG(win1),OBJSEG(TVmywindow()),0);
TVwin_swrite(NIL,"\r\nWindow 0 on top") ;
TVsleep(100) ;
TVwin_top(win3) ;
TVwin_swrite(win3,"\n\rWindow 3 on top again") ;
TVsleep(100) ;
TVwin_topsys(win2) ;
TVwin_swrite(win2,"\n\rWindow 2 now topmost" ) ;
TVsleep(100) ;
TVwin_top(NIL) ;
TVwin_swrite(NIL,"\n\rBack to window 0" ) ;
TVsleep(100) ;
TVkbd_open(NIL,NIL) ; /* make sure keyboard is attached to main window */
TVwin_swrite(NIL,"\r\nPlease open another window, then press a key....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVwin_top(NIL) ;
TVwin_swrite(NIL,"\n\rAbout to hide and then unhide all my windows....") ;
TVsleep(150) ;
TVapp_hide(NIL) ; /* also puts us in background, */
TVsleep(100) ;
TVapp_show(NIL) ;
TVsleep(10) ;
TVapp_gofore(NIL) ; /* so have to force ourself into foreground */
TVwin_swrite(NIL,"\r\nDone!") ;
TVwin_redraw(NIL) ;
TVsleep(50) ;
TVwin_swrite(NIL,"\r\n\nI am about to put myself in the background, and"
"\r\nthen back into the foreground") ;
TVsleep(200) ;
TVapp_goback(NIL) ;
TVsleep(100) ;
TVapp_gofore(NIL) ;
TVwin_swrite(NIL,"\r\nDone!") ;
TVsleep(50) ;
TVwin_free(win3) ;
TVsleep(50) ;
TVwin_free(win2) ;
TVsleep(50) ;
TVwin_free(win1) ;
TVsleep(50) ;
TVwin_frattr(NIL,0x70) ; /* reverse video */
TVwin_redraw(NIL) ; /* make sure physical screen is updated */
/* it seems that writing to multiple windows requires reconnecting the
keyboard to the window you really want to talk to .... */
TVkbd_clrflags(NIL,KBD_ACTIVE) ;
TVkbd_close(NIL) ; /* disconnect keyboard from window */
TVkbd_open(NIL,NIL) ;
TVkbd_setflags(NIL,KBD_ACTIVE) ; /* reconnect to main window and make active */
TVkbd_clear(NIL) ;
TVwin_swrite(NIL,"\r\nPress a key to continue....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
}
/*===============================================================*/
void subtask1(int parent)
{
char kbd_input[16] ;
char mbx_input[32] ;
int mbx_status ;
OBJECT mbx ;
do {
TVkbd_read(NIL,kbd_input,sizeof(kbd_input)) ;
if (kbd_input[0] != 0x1B)
TVwin_swrite(NIL,kbd_input) ;
} while (kbd_input[0] != 0x1B) ;
TVwin_clear(NIL) ;
do {
TVreadmail(NIL,mbx_input, sizeof(mbx_input)) ;
mbx_status = (int) TVmbx_status(NIL) ;
if (mbx_input[0] == '\0')
TVwin_swrite(NIL,"\r\nThat's all, folks!" ) ;
else
{
TVwin_swrite(NIL, "\r\nRead: '") ;
TVwin_swrite(NIL, mbx_input) ;
TVwin_swrite(NIL, "' with status ") ;
write_int(mbx_status) ;
if (OBJSEG(TVmbx_sender(NIL)) == parent)
TVwin_swrite(NIL," from parent") ;
else
TVwin_swrite(NIL," from a stranger") ;
}
} while (mbx_input[0] != '\0') ;
TVsleep(250) ;
TVwin_clear(NIL) ;
TVwin_swrite(NIL,"Test of named mailboxes:\r\n") ;
mbx = TVmbx_new() ;
TVmbx_open(mbx);
TVmbx_name(mbx,"Test Mailbox") ;
TVmbx_clear(mbx) ;
TVmbx_write(TVmbxof(MK_OBJ(parent)),FALSE,0,"Ready",5) ;
TVreadmail(mbx,mbx_input,sizeof(mbx_input)) ;
TVwin_swrite(NIL,"Got '") ;
TVwin_swrite(NIL,mbx_input) ;
TVwin_swrite(NIL,"'") ;
TVsleep(150) ; /* don't ACK right away */
TVmbx_write(TVmbxof(MK_OBJ(parent)),FALSE,0,"Done",4) ;
TVreadmail(NIL,mbx_input,sizeof(mbx_input)) ;
TVmbx_close(mbx) ;
TVmbx_free(mbx) ;
}
void subtask2(int parent)
{
int row = 0, col = 0 ;
int drow, dcol ;
int rows, cols ;
int rep ;
(void) parent ; /* get rid of TurboC's warning about unused parameters */
TVwin_cursor(NIL,0,0) ;
TVwin_hcur(NIL) ;
drow = 1 ;
dcol = 1 ;
for (rep = 0 ; rep < 30 ; rep++)
do {
if (TVmbx_size(NIL) != 0)
{
TVmbx_clear(NIL) ; /* discard messages, only used to notify us */
TVstoptask(NIL) ; /* and suspend ourselves */
}
TVwin_cursor(NIL,row,col) ;
TVwin_swrite(NIL," ") ;
TVqry_size(NIL, &rows, &cols) ;
if (row < 0 || row >= rows-1)
drow = -drow ;
if (col < 0 || col >= cols-1)
dcol = -dcol ;
row += drow ;
col += dcol ;
TVwin_cursor(NIL,row,col) ;
TVwin_swrite(NIL,"+") ;
TVsleep(10) ;
} while (row != 0 || col != 0) ;
}
void stripCRLF(char *buf)
{
char *s = buf + strlen(buf) -1 ;
while (s >= buf && (*s == '\r' || *s == '\n'))
s-- ;
s[1] = '\0' ;
}
void fork_test(void)
{
char key, keys[2], prog[30], arg1[30] ;
OBJECT task1, task2, new_task ;
int count = 0 ;
char *progname ;
char mail[10] ;
TVwin_clear(NIL) ;
TVwin_cursor(NIL,0,0) ;
task1 = TVnew_task(NIL,"Echo keys",0,39,3,40,NULL,1000,subtask1) ;
if (task1 == NIL)
{
TVerrormsg(0,"Insufficient memory or other error--Press ESC",1,0,0,0);
return ;
}
TVsleep(50) ;
task2 = TVnew_task(NIL,"Another task",14,0,10,78,NULL,1000,subtask2) ;
TVwin_swrite(NIL,"Type characters to echo in other window, ESC to quit") ;
do {
key = bioskey(0) ;
keys[0] = key ;
TVkbd_write(TVkbdof(task1),keys,1,0) ;
} while (key != 0x1B) ;
TVsleep(100) ; /* allow time for other window to clear */
TVwin_swrite(NIL,"\r\nType strings to echo in other window, press just RETURN to quit\r\n") ;
TVwin_hcur(NIL) ;
do {
fgets(arg1, sizeof(arg1), stdin) ;
stripCRLF(arg1) ;
TVmbx_write(TVmbxof(task1),FALSE,count++,arg1, strlen(arg1)) ;
} while (strlen(arg1) > 0) ;
TVmbx_clear(NIL) ;
TVwin_swrite(NIL,"\r\n\r\nTesting named mailboxes\r\n") ;
TVreadmail(NIL,mail,sizeof(mail)) ; /* wait for other task to set up mbx */
TVwin_swrite(NIL,"sending... " ) ;
TVmbx_write(TVmbx_find("Test Mailbox"),FALSE,0,"Test successful",15) ;
TVreadmail(NIL,mail,sizeof(mail)) ; /* wait for ACK */
TVwin_swrite(NIL,"got ACK: '") ;
TVwin_swrite(NIL,mail) ;
TVwin_swrite(NIL,"'") ;
TVmbx_write(TVmbxof(task1),FALSE,0,"Quit",4) ;
TVsleep(100) ; /* allow time for other window to close */
TVwin_swrite(NIL,"\r\n\r\nPress a key to continue....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVsendmail(TVmbxof(task2),"",0) ; /* would like to do TVstoptask(task2) */
/* but DV 2.00 only allows suspending */
/* the current process, not others */
TVwin_swrite(NIL,"\r\nThe 'bouncing' plus sign in the other window should"
"\r\nhave stopped moving. Press a key....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVstarttask(task2) ;
TVwin_swrite(NIL,"\r\nIt should have started moving again. Press a key....") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVfreetask(task1) ;
TVfreetask(task2) ; /* make sure the subtasks are both terminated */
TVwin_swrite(NIL,"\r\nOK, now let's load a user program.\r\nProgram's name, including extension: ");
TVwin_hcur(NIL) ;
fgets(prog,sizeof(prog),stdin) ;
stripCRLF(prog) ;
TVwin_swrite(NIL,"\r\nThe program's argument: " ) ;
TVwin_hcur(NIL) ;
fgets(arg1,sizeof(arg1),stdin) ;
stripCRLF(arg1) ;
progname = searchpath(prog) ;
if (progname)
{
TVwin_printf(NIL,"\nInvoking '%s %s'\n",progname,arg1) ;
new_task = TVapp_new(NIL,0,0,20,78,progname,progname,arg1,NULL) ;
if (new_task != NIL)
{
TVwin_swrite(NIL,"\r\nExperiment with switching between this program and "
"\r\nthe one you just invoked. Press a key when done") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVfreetask(new_task) ;
}
else
TVerrormsg(0,"Error loading--not enough memory? ESC to continue",1,0,0,0) ;
}
else
TVwin_printf(NIL,"\n\n\nCouldn't find %s!\n", prog ) ;
}
/*===============================================================*/
void far second_level_interrupt(void)
{
/* note that in this routine, DS/ES/SS are unknown */
TVsound(1000,10) ;
}
void interrupt_test(void)
{
WORD bit = TVgetbit(second_level_interrupt) ;
TVwin_swrite(NIL,"\r\n\r\nPress a key to test second level interrupts") ;
TVwin_hcur(NIL) ;
bioskey(0) ;
TVwin_swrite(NIL,"\r\n\r\nBeeping....") ;
TVsetbit(bit) ;
TVsleep(100) ;
TVfreebit(bit) ;
TVwin_swrite(NIL,"Done!\r\n") ;
}
/*===============================================================*/
void objectq_test(void)
{
OBJECT p = TVptr_new() ;
OBJECT obj ;
char buffer[100] ;
int i, count ;
TVobq_open(NIL) ;
TVkbd_clear(NIL) ;
TVobq_add(NIL,TVmykbd()) ;
TVptr_open(p,NIL) ;
TVptr_setflags(p,1) ;
TVptr_erase(p) ;
TVobq_add(NIL,p) ;
TVwin_clear(NIL) ;
TVwin_title(NIL,"OBJECTQ demo") ;
TVwin_cursor(NIL,0,0) ;
TVwin_origin(NIL,0,0) ;
TVwin_swrite(NIL,"Waiting for input from either the keyboard or a mouse\r\n") ;
TVwin_swrite(NIL,"(a keyboard mouse doesn't count as mouse input)") ;
obj = TVobq_read(NIL) ;
count = TVptr_read(obj,buffer,sizeof(buffer)) ;
TVwin_swrite(NIL,"\r\nGot: ") ;
for (i = 0 ; i < count ; i++)
TVwin_printf(NIL,"%02x ",buffer[i]) ;
TVobq_remove(NIL,p) ; /* don't take input from mouse anymore */
TVptr_close(p) ; /* don't need the object, so free it */
TVptr_free(p) ;
TVsleep(100) ;
TVobq_close(NIL) ;
}
/*===============================================================*/
void field_test(void)
{
char buffer[50] ;
BYTE *fields ;
int status, len ;
TVwin_title(NIL,"Field Demo") ;
TVwin_clear(NIL) ;
TVwin_gotoxy(NIL,0,0) ;
TVwin_swrite(NIL,"Field-mode test\r\n"
"Cursor should be \031 there\r\n"
"Enter a number: Enter a string:\r\n"
"Forced uppercase string: With value: \r\n"
"Press RETURN when done, or click here: ") ;
fields = TVfld_build_header(5,F_ALLOWKBD|F_READARRAY,0x70,0x0F) ;
TVfld_build_entry(fields,1,2,16,2,18,F_FILLIN,F_NEXT|F_NUMBER|F_CLEAR,1,0) ;
TVfld_build_entry(fields,2,2,35,2,50,F_FILLIN,F_NEXT|F_CLEAR,1,0) ;
TVfld_build_entry(fields,3,3,25,3,30,F_FILLIN,F_NEXT|F_UPPER|F_CLEAR,1,0) ;
TVfld_build_entry(fields,4,3,44,3,57,F_FILLIN,F_NEXT|F_CLEAR,1,0) ;
TVfld_build_entry(fields,5,4,39,4,42,F_MENU,'\r',0x70,0) ;
TVwin_stream(NIL,fields) ;
TVfld_swrite(NIL,4,"default") ;
TVfld_attr(NIL,4,0x70) ;
TVfld_cursor(NIL,1) ; /* position cursor in first field */
TVwin_redraw(NIL) ;
TVfld_altmode(NIL,TRUE) ;
len = TVkbd_read(NIL,buffer,sizeof(buffer)) ;
status = (int) TVkbd_status(NIL) ;
TVfld_altmode(NIL,FALSE) ;
free(fields) ; /* now we can finally free the stream */
TVwin_gotoxy(NIL,0,6) ;
TVwin_printf(NIL,"Got '%.*s'\r\nStatus was %d\r\nPress a key....",len,buffer,status) ;
TVwin_hcur(NIL) ;
bioskey(0) ;
}
/*===============================================================*/
void main()
{
/* initialize everything and return DESQview version number */
if (DVinit() == 0)
{
SE_STRC("This program requires DESQview 2.0 or later\n");
exit(1);
}
stream_test() ;
TVerrormsg(0,"TEST ERROR MESSAGE - press ESC",1,0,0,0);
TVsound(500,1);
TVsound(880,2);
TVsound(440,3);
notify_test() ;
timer_test() ;
pointer_test();
field_test() ;
fork_test() ;
interrupt_test() ;
objectq_test() ;
multiwindow_test() ;
/* quit DESQview API */
DVexit() ;
}
/* End of INT15DEM.C */